package pt.fct.mpc.lastfm.search;

import java.net.MalformedURLException;
import java.net.URL;

abstract public class SearchHit
	implements SearchResult
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 6299163347718659501L;
	protected String name;
	protected int search_position;
	protected URL url;
	protected String image_small = null;
	protected String image_default = null;
	protected boolean streamable = false;
	
	protected SearchHit(String name, String url, int search_position)
	{
		this.setName(name);
		this.setURL(url);
		this.setSearchPosition(search_position);	
	}
	
	public String getName()
	{
		return name;
	}
	
	public void setName(String name)
	{
		this.name = name;
	}
	
	public int getSearchPosition()
	{
		return search_position;
	}
	
	public void setSearchPosition(int searchPosition)
	{
		search_position = searchPosition;
	}
	
	public URL getURL()
	{
		return url;
	}
	
	public void setURL(URL url)
	{
		this.url = url;
	}
	
	public void setURL(String url)
	{
		String tmp = url.trim();
		if (!tmp.startsWith("http://"))
			tmp = "http://"+tmp;
		
		try
		{
			this.url = new URL(tmp);
		} catch (MalformedURLException e)
		{
			e.printStackTrace();
			this.url = null;
		}
	}
	
	public String getSmallImage()
	{
		return image_small;
	}
	
	public void setSmallImage(String imageSmall)
	{
		image_small = imageSmall;
	}
	
	public String getDefaultImage()
	{
		return image_default;
	}
	
	public void setDefaultImage(String imageDefault)
	{
		image_default = imageDefault;
	}
	
	public boolean isStreamable()
	{
		return streamable;
	}
	
	public void setStreamable(boolean streamable)
	{
		this.streamable = streamable;
	}

	@Override
	abstract public String toString();
	
}
